package com.yeheng.test.homework2;

/**
 * @PackgeName: com.yeheng.test.homework2
 * @ClassName: MyThread
 * @Author: YH
 * Date: 2021/1/1 19:04
 * project name: homework1
 * @Version:
 * @Description:
 */
public class MyThread implements Runnable{

    private int i = 100;


    @Override
    public  void run() {
        while (true) {
            synchronized (MyThread.class) {
               if (i>0){
                   try {
                       Thread.sleep(200);
                       System.out.println(Thread.currentThread().getName() + "正在买票，还剩:" + i-- + "张票");
                   } catch (InterruptedException e) {
                       e.printStackTrace();
                   }
               }else {
                   break;
               }
            }
        }
    }
}
